

use $data/Figures_Final.dta, replace 

xtset apt timestamp 

gen weekspast=.
label var weekspast "Weeks Since Treatment"

// COEFFICIENTS AND THE UPPER AND LOWER BOUND FOR THE
// CONFIDENCE INTERVALS FOR THE HEALTH AND FINANCIAL
// TREATMENT EFFECTS
gen coeff_fin=.
gen lci_fin=.
gen uci_fin=.
gen coeff_health=.
gen lci_health=.
gen uci_health=.

gen include=0

order apt timestamp weekspast coeff_fin lci_fin uci_fin coeff_health lci_health uci_health include



forvalues i=1/12{

replace weekspast=`i' in `i'

replace include=1 if day<=mdy(2,18,2014)+`i'*7

xtgls lnenergy hour_temp post finpost healthpost tt tt2 tt3 i.dayofweek i.hour i.apt if include==1, panels(h) corr(psar1) force

replace coeff_fin=100*(_b[finpost]) if weekspast==`i'
replace lci_fin=100*(_b[finpost]-invttail(e(df_pear),.025)*_se[finpost]) in `i'
replace uci_fin=100*(_b[finpost]+invttail(e(df_pear),.025)*_se[finpost]) in `i'

replace coeff_health=100*(_b[healthpost]) if weekspast==`i'
replace lci_health=100*(_b[healthpost]-invttail(e(df_pear),.025)*_se[healthpost]) in `i'
replace uci_health=100*(_b[healthpost]+invttail(e(df_pear),.025)*_se[healthpost]) in `i'

}
//


drop include

save $data/Figures_Use_Final.dta, replace
